<?php
/**
* Abstarct command
* @package WKernel
*/
require_once 'WKernel/Command/Interface.php';
abstract class WK_Command_Abstract implements WK_Command_Interface {
	protected $params = array();
	/**
	 * 
	 * <code>
	 * schema
	 * |-[param_name]
	 * | | |-type
	 * | | |-default
	 * | | |-mandatory
	 * </code>
	 * @var unknown_type
	 */
	protected $paramschema = array();
	
	public function __construct($params) {
		$this->params = $this->castParams($params);			
	}
	
	private function castParams($params) {
		foreach ($this->paramschema as $name => $constraints) {
			if(empty($params[$name])) {
				if(@$constraints['mandatory'])
					throw new WK_Error('Paramter ' . $name . ' is mandatory!', WERR_WRONG_CMD_PARAMETERS);
				if(isset($constraints['default']) && !isset($params[$name]))
					$params[$name] = $constraints['default'];
			}
			//TODO: may be some day we will implement type casting... 
		}		
		return $params;
	} 
}